//
//  ClassDataTool.m
//  MarryMe
//
//  Created by lanou3g on 16/1/9.
//  Copyright © 2016年 revocher. All rights reserved.
//

#import "ClassDataTool.h"

@implementation ClassDataTool

+(void)requestDataWithUrl:(NSString *)urlStr
            WithBackBlock:(backBlock)backBlock{
    
    NSURL *url = [NSURL URLWithString:urlStr];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        // NSLog(@"%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]);
        if (nil == error) {
            id object = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            dispatch_async(dispatch_get_main_queue(), ^{
                backBlock(object);
            });
        }else{
            NSLog(@"%@",error);
        }
        
    } ];
    
    [dataTask resume];
    
    
}


@end
